package com.blog.cmrpersonalblog.enums;

/**
 * 文件上传类型枚举
 */
public enum FileUploadType {
    
    /**
     * 用户头像
     */
    AVATAR("avatar", "用户头像", "/avatars", 2 * 1024 * 1024), // 2MB
    
    /**
     * 文章封面
     */
    ARTICLE_COVER("article_cover", "文章封面", "/articles/covers", 5 * 1024 * 1024), // 5MB
    
    /**
     * 评论图片
     */
    COMMENT_IMAGE("comment_image", "评论图片", "/comments/images", 3 * 1024 * 1024), // 3MB
    
    /**
     * 通用图片
     */
    GENERAL_IMAGE("general_image", "通用图片", "/images", 10 * 1024 * 1024); // 10MB
    
    private final String code;
    private final String description;
    private final String relativePath;
    private final long maxSize;
    
    FileUploadType(String code, String description, String relativePath, long maxSize) {
        this.code = code;
        this.description = description;
        this.relativePath = relativePath;
        this.maxSize = maxSize;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }
    
    public String getRelativePath() {
        return relativePath;
    }
    
    public long getMaxSize() {
        return maxSize;
    }
    
    /**
     * 根据代码获取枚举
     */
    public static FileUploadType fromCode(String code) {
        for (FileUploadType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("不支持的文件上传类型: " + code);
    }
}
